package com.changgou.controller;

import com.alibaba.fastjson.JSONObject;
import com.changgou.config.ResultVo;
import com.changgou.config.myinterface.AutoIdempotent;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import com.changgou.service.TestService;
import com.changgou.service.TokenService;

import javax.annotation.Resource;

@RestController
public class BusinessController {


    @Resource
    private TokenService tokenService;

    @Resource
    private TestService testService;


    @PostMapping("/get/token")
    public String  getToken(){
        String token = tokenService.createToken();
        if (StringUtils.isNotEmpty(token)) {
            ResultVo resultVo = new ResultVo();
            resultVo.setCode(200);
            resultVo.setMessage("成功");
            resultVo.setData(token);
            return JSONObject.toJSONString(resultVo);
        }
        return StringUtils.EMPTY;
    }


    @AutoIdempotent
    @PostMapping("/test/Idempotence")
    public String testIdempotence() {
        String businessResult = testService.testIdempotence();
        if (StringUtils.isNotEmpty(businessResult)) {
            ResultVo successResult = ResultVo.getSuccessResult(businessResult);
            return JSONObject.toJSONString(successResult);
        }
        return StringUtils.EMPTY;
    }
}